import http from '../../utils/http'
import type { ApiResponse, PageResult } from '../../utils/ApiResponse'
import {Orders, PageOrders} from "./types/orders.dto.ts";

// 获取所有订单数据
export const getAllOrders = (data: PageOrders): Promise<PageResult<Object>> => {
    return http.get(`/orders/info`, {
        params: {
            page: data.page,
            limit: data.limit,
            userName: data.userName,
            status: data.status,
            startOrderTime: data.startOrderTime,
            endOrderTime: data.endOrderTime,
        }
    })
}

// 更新订单数据
export const saveOrderInfo = (data: any): Promise<ApiResponse<Orders>> => {
    return http.post(`/orders/update`, data)
}

// 根据id获取订单数据
export const getOrderInfoById = (id: number): Promise<ApiResponse<Orders>> => {
    return http.get(`/orders/info/${id}`)
}

// 根据订单ids批量发货
export const batchDelivery = (ids: any): Promise<ApiResponse<Object>> => {
    return http.post(`/orders/batchDelivery`,ids)
}

// 删除订单
export const deleteOrder = (id: number): Promise<ApiResponse<Object>> => {
    return http.delete(`/orders/delete/${id}`)
}

// 添加订单数据
export const addOrder = (data: Orders): Promise<ApiResponse<Object>> => {
    return http.post(`/orders/add`,data)
}
